package com.com.ruanmeng.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.os.Environment;
import android.widget.ImageView;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Tools {
	/**
	 * ����Ƿ����SDCard
	 * @return
	 */
	public static boolean hasSdcard(){
		String state = Environment.getExternalStorageState();
		if(state.equals(Environment.MEDIA_MOUNTED)){
			return true;
		}else{
			return false;
		}
	}
	public static void getImgFromSD(ImageView iv, int width) {
		File file = new File(Environment.getExternalStorageDirectory()+"/photo_jq.jpg");
		if(file.exists()) {
			Options opts = new Options();
			opts.inJustDecodeBounds = true;
			BitmapFactory.decodeFile(file.getAbsolutePath(), opts);
			opts.inSampleSize = opts.outWidth/width;
			opts.inJustDecodeBounds = false;
			Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath(), opts);
			iv.setImageBitmap(bm);
		}
	}
	/**
	 * ��ȡ�汾��
	 * @return ��ǰӦ�õİ汾��
	 */
	public static String getVersion(Context context) {
		String version = "";
		try {
			PackageManager manager = context.getPackageManager();
			PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
			version = info.versionName;
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return version;
	}

	// 判断是汉子
	public static boolean ishanzi(String str) {

		Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]+");

		Matcher isNum = pattern.matcher(str);

		if (!isNum.matches()) {

			return false;

		}

		return true;

	}
	
}
